package homeWork;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class test02 {
    public static void main(String[] args) throws IOException{
        File dir = new File(".");
        if (dir.isDirectory()){
           File[] subs = dir.listFiles(file->file.isFile());
            for (int i=0;i<subs.length;i++){
                File file = subs[i];
                String filename = subs[i].getName();
                String name1 = filename.substring(0,filename.indexOf("."));
                String name2 = filename.substring(filename.indexOf(".")+1);
                String newFileName = name1+"_cp."+name2;
                FileInputStream fis = new FileInputStream(file);
                FileOutputStream fos = new FileOutputStream(newFileName);
                byte[] data = new byte[1024*10];
                int len;
                while((len = fis.read(data))!=-1){
                    fos.write(data,0,len);
                }
                fis.close();
                fos.close();

            }
        }
        System.out.println("全部复制完毕");
    }
}
